home *** CD-ROM | disk | FTP | other *** search
- VERSION 5.00
- Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
- Begin VB.Form frmSubEdge2
- Caption = "SubEdge2 []"
- ClientHeight = 2910
- ClientLeft = 165
- ClientTop = 735
- ClientWidth = 5175
- LinkTopic = "Form2"
- ScaleHeight = 2910
- ScaleWidth = 5175
- StartUpPosition = 3 'Windows Default
- Begin MSComDlg.CommonDialog dlgOpenFile
- Left = 0
- Top = 840
- _ExtentX = 847
- _ExtentY = 847
- _Version = 393216
- End
- Begin VB.PictureBox picOriginal
- AutoSize = -1 'True
- Height = 2775
- Left = 120
- ScaleHeight = 181
- ScaleMode = 3 'Pixel
- ScaleWidth = 157
- TabIndex = 1
- Top = 0
- Width = 2415
- End
- Begin VB.PictureBox picResult
- Height = 2775
- Left = 2640
- ScaleHeight = 181
- ScaleMode = 3 'Pixel
- ScaleWidth = 157
- TabIndex = 0
- Top = 0
- Width = 2415
- End
- Begin VB.Menu mnuFile
- Caption = "&File"
- Begin VB.Menu mnuFileOpen
- Caption = "&Open..."
- Shortcut = ^O
- End
- Begin VB.Menu mnuFileSaveAs
- Caption = "Save &As..."
- Shortcut = ^A
- End
- End
- Attribute VB_Name = "frmSubEdge2"
- Attribute VB_GlobalNameSpace = False
- Attribute VB_Creatable = False
- Attribute VB_PredeclaredId = True
- Attribute VB_Exposed = False
- Option Explicit
- ' Arrange the controls.
- Private Sub ArrangeControls()
- ' Position the result PictureBox.
- picResult.Move _
- picOriginal.Left + picOriginal.Width + 120, _
- picOriginal.Top, _
- picOriginal.Width, _
- picOriginal.Height
- picResult.Cls
- ' This makes the image resize itself to
- ' fit the picture.
- picResult.Picture = picResult.Image
- ' Make the form big enough.
- Width = picResult.Left + picResult.Width + _
- Width - ScaleWidth + 120
- Height = picResult.Top + picResult.Height + _
- Height - ScaleHeight + 120
- DoEvents
- End Sub
- ' Transform the image.
- Private Sub TransformImage()
- Dim pixels() As RGBTriplet
- Dim new_pixels() As RGBTriplet
- Dim bits_per_pixel As Integer
- Dim brightness As Integer
- Dim r As Integer
- Dim g As Integer
- Dim b As Integer
- Dim X As Integer
- Dim Y As Integer
- Dim i As Integer
- Dim j As Integer
- ' Get the pixels from picOriginal.
- GetBitmapPixels picOriginal, pixels, bits_per_pixel
- ' Allocate the new_pixels array.
- ReDim new_pixels( _
- LBound(pixels, 1) To UBound(pixels, 1), _
- LBound(pixels, 2) To UBound(pixels, 2))
- ' Set the pixel color values.
- For Y = 1 To picOriginal.ScaleHeight - 2
- For X = 1 To picOriginal.ScaleWidth - 2
- With pixels(X, Y)
- r = 0
- g = 0
- b = 0
- For i = -1 To 1
- For j = -1 To 1
- r = r + Abs(CInt(.rgbRed) - pixels(X + i, Y + j).rgbRed)
- g = g + Abs(CInt(.rgbGreen) - pixels(X + i, Y + j).rgbGreen)
- b = b + Abs(CInt(.rgbBlue) - pixels(X + i, Y + j).rgbBlue)
- Next j
- Next i
- If r < 0 Then r = 0
- If r > 255 Then r = 255
- If g < 0 Then g = 0
- If g > 255 Then g = 255
- If b < 0 Then b = 0
- If b > 255 Then b = 255
- new_pixels(X, Y).rgbRed = r
- new_pixels(X, Y).rgbGreen = g
- new_pixels(X, Y).rgbBlue = b
- End With
- Next X
- Next Y
- ' Set picResult's pixels.
- SetBitmapPixels picResult, bits_per_pixel, new_pixels
- picResult.Picture = picResult.Image
- End Sub
- ' Start in the current directory.
- Private Sub Form_Load()
- picOriginal.AutoSize = True
- picOriginal.ScaleMode = vbPixels
- picOriginal.AutoRedraw = True
- picResult.ScaleMode = vbPixels
- picResult.AutoRedraw = True
- dlgOpenFile.CancelError = True
- dlgOpenFile.InitDir = App.Path
- dlgOpenFile.Filter = _
- "Bitmaps (*.bmp)|*.bmp|" & _
- "GIFs (*.gif)|*.gif|" & _
- "JPEGs (*.jpg)|*.jpg;*.jpeg|" & _
- "Icons (*.ico)|*.ico|" & _
- "Cursors (*.cur)|*.cur|" & _
- "Run-Length Encoded (*.rle)|*.rle|" & _
- "Metafiles (*.wmf)|*.wmf|" & _
- "Enhanced Metafiles (*.emf)|*.emf|" & _
- "Graphic Files|*.bmp;*.gif;*.jpg;*.jpeg;*.ico;*.cur;*.rle;*.wmf;*.emf|" & _
- "All Files (*.*)|*.*"
- End Sub
- ' Load the indicated file.
- Private Sub mnuFileOpen_Click()
- Dim file_name As String
- ' Let the user select a file.
- On Error Resume Next
- dlgOpenFile.Flags = cdlOFNFileMustExist + cdlOFNHideReadOnly
- dlgOpenFile.ShowOpen
- If Err.Number = cdlCancel Then
- Exit Sub
- ElseIf Err.Number <> 0 Then
- Beep
- MsgBox "Error selecting file.", , vbExclamation
- Exit Sub
- End If
- On Error GoTo 0
- Screen.MousePointer = vbHourglass
- DoEvents
- file_name = Trim$(dlgOpenFile.FileName)
- dlgOpenFile.InitDir = Left$(file_name, Len(file_name) _
- - Len(dlgOpenFile.FileTitle) - 1)
- Caption = "SubEdge2 [" & dlgOpenFile.FileTitle & "]"
- ' Open the original file.
- On Error GoTo LoadError
- picOriginal.Picture = LoadPicture(file_name)
- On Error GoTo 0
- ' Make picResult the same size and position it.
- ArrangeControls
- ' Make picResult show the same image.
- picResult.Picture = picOriginal.Picture
- DoEvents
- ' Perform the enhancement.
- TransformImage
- Screen.MousePointer = vbDefault
- Exit Sub
- LoadError:
- Screen.MousePointer = vbDefault
- MsgBox "Error " & Format$(Err.Number) & _
- " opening file '" & file_name & "'" & vbCrLf & _
- Err.Description
- End Sub
- ' Save the transformed image.
- Private Sub mnuFileSaveAs_Click()
- Dim file_name As String
- ' Let the user select a file.
- On Error Resume Next
- dlgOpenFile.Flags = cdlOFNOverwritePrompt + cdlOFNHideReadOnly
- dlgOpenFile.ShowSave
- If Err.Number = cdlCancel Then
- Exit Sub
- ElseIf Err.Number <> 0 Then
- Beep
- MsgBox "Error selecting file.", , vbExclamation
- Exit Sub
- End If
- On Error GoTo 0
- Screen.MousePointer = vbHourglass
- DoEvents
- file_name = Trim$(dlgOpenFile.FileName)
- dlgOpenFile.InitDir = Left$(file_name, Len(file_name) _
- - Len(dlgOpenFile.FileTitle) - 1)
- Caption = "SubEdge2 [" & dlgOpenFile.FileTitle & "]"
- ' Save the transformed image into the file.
- On Error GoTo SaveError
- SavePicture picResult.Picture, file_name
- On Error GoTo 0
- Screen.MousePointer = vbDefault
- Exit Sub
- SaveError:
- Screen.MousePointer = vbDefault
- MsgBox "Error " & Format$(Err.Number) & _
- " saving file '" & file_name & "'" & vbCrLf & _
- Err.Description
- End Sub
-